package main

import (
  "log"

  "github.com/howeyc/fsnotify"
)

//监控文件的
func main() {
  watcher, err := fsnotify.NewWatcher()
  if err != nil {
    log.Fatal(err)
  }

  done := make(chan bool)

  // Process events
  go func() {
    for {
      select {
      case ev := <-watcher.Event:
        log.Println("event:", ev)
      case err := <-watcher.Error:
        log.Println("error:", err)
      }
    }
  }()

  //err = watcher.Watch("test_fs.log")
  err = watcher.WatchFlags("test_fs.log",fsnotify.FSN_RENAME)
  if err != nil {
    log.Fatal(err)
  }
  
  // Hang so program doesn't exit
  <-done

  /* ... do stuff ... */
  watcher.Close()
}